package com.my.study.common;

import com.my.study.common.message.Message;

import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * @author Carlos
 * @version 1.0
 * @Description 客户端连接服务端线程
 * @date 2021/7/18 14:13
 **/
public class ClientConnectServerThread extends Thread{

    private Socket socket;

    public ClientConnectServerThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        // 因为需要在后台与服务器通信，需要while循环
        while (true) {
            try {
                System.out.println("客户端线程，等待从服务器端读取消息...");
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                // 如果服务器没有发生message，会一直阻塞在这里；
                Message message = (Message) ois.readObject();
                // TODO

            } catch (Exception e) {
                e.printStackTrace();
            }


        }
    }

    public Socket getSocket() {
        return socket;
    }


}
